package com.fulu.game.bi.controller.market;

import com.fulu.game.bi.common.controller.BaseController;
import com.fulu.game.bi.entity.po.market.UserRepurchaseStat;
import com.fulu.game.bi.entity.vo.Result;
import com.fulu.game.bi.entity.vo.common.NameMsgVO;
import com.fulu.game.bi.entity.vo.market.UserRepurchaseVO;
import com.fulu.game.bi.redis.service.market.UserRepurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 市场/增长 - 用户复购
 */
@RequestMapping("/api/v1/user-repurchase")
@RestController
public class UserRepurchaseController extends BaseController {
    @Autowired
    private UserRepurchaseService userRepurchaseService;

    /**
     * 列表查询
     */
    @PostMapping("/query")
    public Result<List<UserRepurchaseStat>> query(UserRepurchaseVO vo) {
        List list = userRepurchaseService.list(vo);
        return Result.success().data(list).msg("查询成功");
    }

    /**
     * 导出查询
     */
    @PostMapping("/export")
    public void export(UserRepurchaseVO vo) {
        userRepurchaseService.export(vo);
    }

    /**
     * 折线图类型
     * @return
     */
    @RequestMapping("/stat")
    public Result<List<NameMsgVO>> stat(Integer statType) {
        Map<Integer, String> repurchaseTypeMap = new HashMap<>();
        repurchaseTypeMap.put(1, "次");
        repurchaseTypeMap.put(2, "天");
        final String site = repurchaseTypeMap.get(statType);
        Map<String, String> cacheMap = new LinkedHashMap<>();
        cacheMap.put("1"+site+"用户数", "totalNum1");
        cacheMap.put("1"+site+"用户比率", "totalRatio1");
        cacheMap.put("2"+site+"用户", "totalNum2");
        cacheMap.put("2"+site+"用户比率", "totalRatio2");
        cacheMap.put("3"+site+"及以上用户", "totalNum3");
        cacheMap.put("3"+site+"及以上用户比率", "totalRatio3");
        cacheMap.put("1"+site+"新用户数", "newNum1");
        cacheMap.put("1"+site+"新用户比率", "newRatio1");
        cacheMap.put("2"+site+"新用户", "newNum2");
        cacheMap.put("2"+site+"新用户比率", "newRatio2");
        cacheMap.put("3"+site+"及以上新用户", "newNum3");
        cacheMap.put("3"+site+"及以上新用户比率", "newRatio3");
        cacheMap.put("1"+site+"老用户数", "oldNum1");
        cacheMap.put("1"+site+"老用户比率", "oldRatio1");
        cacheMap.put("2"+site+"老用户", "oldNum2");
        cacheMap.put("2"+site+"老用户比率", "oldRatio2");
        cacheMap.put("3"+site+"及以上老用户", "oldNum3");
        cacheMap.put("3"+site+"及以上老用户比率", "oldRatio3");
        List<NameMsgVO> list = cacheMap.entrySet().stream()
                .map(entry -> {
                    NameMsgVO idNameVO = new NameMsgVO();
                    idNameVO.setName(entry.getValue());
                    idNameVO.setMsg(entry.getKey());
                    return idNameVO;
                })
                .collect(Collectors.toList());

        return Result.success().data(list).msg("获取成功");
    }
}
